<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:90:"E:\wamp\www\dataerqi\mayun\zhongping\tp5\public/../application/admin\view\admin\index.html";i:1497872938;}*/ ?>
<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>管理员列表</title>
    <!--加载CSS-->
    <link rel="stylesheet" type="text/css" href="/static/zwb/bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/zwb/bootstrap/reset.css" />
    <link rel="stylesheet" type="text/css" href="/static/zwb/bootstrap/css/toastr.min.css" />
</head>
<body>
<div class="container">
    <div class="col-md-12 bg-primary p20">
        <h1 class="glyphicon glyphicon-user">管理员列表</h1>
        <hr>
        <a href="<?php echo url('rest/user/index'); ?>" class="btn btn-default">用户列表页</a>
        <a href="<?php echo url('rest/user/create'); ?>" class="btn btn-default">添加页</a>
    </div>
    <div class="clearfix"></div>

    
    <div class="row mt50">
        <div class="col-md-6">
            <table class="table table-hover bg-info">
                <tr>
                    <th>ID</th>
                    <th>NAME</th>
                    <th>POWER</th>
                    <th>ACTION</th>
                </tr>
                <?php if(is_array($list) || $list instanceof \think\Collection || $list instanceof \think\Paginator): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;if($mod == '0'): ?>

                <tr>
                    <td><?php echo $v['id']; ?></td>
                    <td><?php echo $v['name']; ?></td>
                    <td><?php echo $v['power']; ?></td>
                    <td class="col-md-6">
                        <a href="<?php echo url('rest/user/readpage', ['id'=>$v['id']]); ?>" class="btn btn-default btn-xs">查看信息(页)</a>
                        <button data-id="<?php echo $v['id']; ?>" class="btn btn-default btn-xs show-btn" data-toggle="modal" data-target="#myModal">查看信息(框)</button>
                        <a href="<?php echo url('rest/user/edit',['id'=>$v['id']]); ?>" class="btn btn-primary btn-xs">编辑</a>
                        <button data-id="<?php echo $v['id']; ?>" class="btn btn-danger btn-xs del-btn">删除</button>
                    </td>
                </tr>
                <?php endif; endforeach; endif; else: echo "" ;endif; ?>
            </table>
        </div>
        <div class="col-md-6">
            <table class="table table-hover bg-info">
                <tr>
                    <th>ID</th>
                    <th>NAME</th>
                    <th>POWER</th>
                    <th>ACTION</th>
                </tr>
                <?php if(is_array($list) || $list instanceof \think\Collection || $list instanceof \think\Paginator): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;if($mod == '1'): ?>

                <tr>
                    <td><?php echo $v['id']; ?></td>
                    <td><?php echo $v['name']; ?></td>
                    <td><?php echo $v['power']; ?></td>
                    <td class="col-md-6">
                        <a href="<?php echo url('rest/user/readpage', ['id'=>$v['id']]); ?>" class="btn btn-default btn-xs">查看信息(页)</a>
                        <button data-id="<?php echo $v['id']; ?>" class="btn btn-default btn-xs show-btn" data-toggle="modal" data-target="#myModal">查看信息(框)</button>
                        <a href="<?php echo url('rest/user/edit',['id'=>$v['id']]); ?>" class="btn btn-primary btn-xs">编辑</a>
                        <button data-id="<?php echo $v['id']; ?>" class="btn btn-danger btn-xs del-btn">删除</button>
                    </td>
                </tr>
                <?php endif; endforeach; endif; else: echo "" ;endif; ?>
            </table>
        </div>
    </div>
</div>


<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">
                    用户[<u></u>]的详细信息
                </h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-3">
                        <img src="/static/zwb/bootstrap/face/batman.jpg" width="100">
                    </div>
                    <div class="col-md-9">
                        <h3></h3>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>



<!--加载JS-->
<script type="text/javascript" src="/static/zwb/bootstrap/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/zwb/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/zwb/bootstrap/js/toastr.min.js"></script>


<script>
    $(function () {
        // 触发用户删除
        $('.del-btn').click(function () {
            var ac_id = $(this).attr('data-id');
            console.log('删除的ID为:', ac_id);

            if (confirm('您确定要 [ 删 除 ] 该用户么?')) {
                var obj = $(this).parents('tr');
                // console.log(obj);
                delAjax(ac_id, obj);// 执行删除操作
            }
        });

        // 触发查询单条用户
        $('.show-btn').click(function () {
            var ac_id = $(this).attr('data-id');
            console.log('查看单条数据,ID为:', ac_id);

            showAjax(ac_id); //AJAX查询
        })

    });


    // 设置弹框参数
    toastr.options = {
        closeButton: true,//是否显示关闭按钮
        progressBar: true,//实现显示计时条
        timeOut: "3000",//自动关闭时间
        positionClass: "toast-bottom-left",//提示位置
        // toast-top-full-width 顶端，宽度铺满整个屏幕
        // toast-top-right  顶端右边
    };

    // 执行AJAX 查询单条数据
    function showAjax(id){
        $.ajax({
            type: 'get',
            url: '/users/' + id,
            dateType: 'json',
            success:function (data){
                console.log(data);
                if (data.status) {
                    // 填充信息
                    $('.modal-title u').html(data.title);
                    var msg = data.datas.id+'/'+data.datas.name+'/'+data.datas.age+'/'+data.datas.sex+'/'+data.datas.province;
                    $('.modal-body h3').html(msg);

                } else {

                }
            },
            error: function () {
                // AJAX执行失败
                alert('ajax操作失败');
            }
        });
    }

    // 执行AJAX删除的操作
    function delAjax(id, obj) {
        // console.log(id);
        $.ajax({
            type: 'delete',
            url: '/users/' + id,
            dateType: 'json',
            success: function (data) {
                if (data.status) {
                    // console.log(data);
                    // console.log('删除成功');
                    toastr.success(data.info);
                    //  将指定条目 节点删除
                    obj.remove();
                } else {
                    //console.log('删除失败');
                    toastr.error(data.info,'FBI WARNING: ');
                }
            },
            error: function () {
                // AJAX执行失败
                alert('ajax操作失败');
            }
        });
    }
</script>

</body>
</html>